# -*- coding:utf-8 -*-

import gpiozero
import RPi.GPIO as GPIO

def initMotor():
	global motorL
	global motorR
	# left motor pwm
	GPIO.setup(02,GPIO.OUT)
	motorL = GPIO.PWM(02,50)
	motorL.start(0)

	# right motor pwm
	GPIO.setup(03,GPIO.OUT)
	motorR = GPIO.PWM(03,50)
	motorR.start(0)

	# left motor a,b
	GPIO.setup(06,GPIO.OUT)
	GPIO.setup(13,GPIO.OUT)

	# right motor a,b
	GPIO.setup(19,GPIO.OUT)
	GPIO.setup(26,GPIO.OUT) 

def forward(speed):
	global motorL
	global motorR
	motorL.ChangeDutyCycle(speed)
	motorR.ChangeDutyCycle(speed)
	GPIO.output(06,1)
	GPIO.output(13,0)
	GPIO.output(19,1)
	GPIO.output(26,0)

def left(speed):
	global motorL
	global motorR
	motorL.ChangeDutyCycle(speed)
	motorR.ChangeDutyCycle(speed)
	GPIO.output(06,0)
	GPIO.output(13,1)
	GPIO.output(19,1)
	GPIO.output(26,0)

def right(speed):
	global motorL
	global motorR
	motorL.ChangeDutyCycle(speed)
	motorR.ChangeDutyCycle(speed)
	GPIO.output(06,1)
	GPIO.output(13,0)
	GPIO.output(19,0)
	GPIO.output(26,1)

def back(speed):
	global motorL
	global motorR
	motorL.ChangeDutyCycle(speed)
	motorR.ChangeDutyCycle(speed)
	GPIO.output(06,0)
	GPIO.output(13,1)
	GPIO.output(19,0)
	GPIO.output(26,1)

